package com.xcx.eduservice.controller.aclcontroller;

import com.xcx.commonuntils.returnuntls.ReturnMessage;
import com.xcx.commonuntils.returnuntls.ReturnMessageUtils;
import com.xcx.eduservice.client.MinioFengClient;
import com.xcx.eduservice.entity.feignentity.FileSystem;
import com.xcx.eduservice.entity.aclentity.User;
import com.xcx.eduservice.request.feignrequest.GetUserFilesRequest;
import com.xcx.eduservice.request.aclrequest.userrequest.*;
import com.xcx.eduservice.response.AssignResponse;
import com.xcx.eduservice.service.UserService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-01-12
 */
@Api(tags = "用户管理系统")
@RestController
@RequestMapping("/acl/user")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
@CrossOrigin
public class UserController {


    final private UserService userService;
    final private MinioFengClient minioFengClient;



    @ApiOperation(value = "获取管理用户分页列表")
    @PostMapping("quaryList")
    public ReturnMessage<Object> quaryList(UserQueryList respVo) {


        return userService.quaryList(respVo);
    }


    /**
     * 超级管理员手动新增用户
     */
    @ApiOperation(value = "管理员新增用户")
    @PostMapping("save")
    public ReturnMessage<User> addUserByAdmin(@RequestBody AddUseRequest addUseRequest) {
        return userService.addUserByAdmin(addUseRequest);
    }




    /**
     * 修改用户
     */
    @ApiOperation(value = "修改用户信息")
    @PutMapping("update")
    public ReturnMessage<User> updateById(@RequestBody UserUpdateRequest respVo) {

        return userService.updateUser(respVo);
    }


    @ApiOperation(value = "单个删除用户")
    @DeleteMapping("remove/{id}")
    public ReturnMessage<User> remove(@ApiParam(name = "id", value = "用户id", required = true)
                                      @PathVariable String id) {
        userService.removeById(id);
        return ReturnMessageUtils.success();
    }

    @ApiOperation(value = "根据id列表批量删除用户")
    @DeleteMapping("batchRemove")
    public ReturnMessage<User> batchRemove(@RequestBody UserBatchRemove respVo) {
        List<String> ids = respVo.getIds();
        userService.removeByIds(ids);
        return ReturnMessageUtils.success();
    }


    @ApiOperation(value = "根据用户获取角色数据")
    @PostMapping("toAssign")
    public ReturnMessage<AssignResponse> toAssign(@RequestBody UserGetProcessionRequest respVo) {



        return userService.toAssign(respVo);
    }



    @ApiOperation(value = "测试微服务远程调用接口")
    @PostMapping("fen")
    public ReturnMessage<Object> fen(@RequestBody GetUserFilesRequest respVo) {

        ReturnMessage<List<FileSystem>> userFiles = minioFengClient.getUserFiles(respVo);


        return ReturnMessageUtils.success(userFiles);
    }









//    @ApiOperation(value = "根据用户分配角色")
//    @PostMapping("/doAssign")
//    public ReturnMessage<User> doAssign(@RequestParam String userId, @RequestParam String[] roleId) {
//        roleService.saveUserRoleRealtionShip(userId, roleId);
//        return ReturnMessageUtils.success();
//    }
}

